<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import {mRequest} from '@/utils/request'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      visible: false,

      dataFormConfig: {
        vouchAccount: {
          label: '收款账户',
          type: 'list',
          list: [],
          default: 1
        },
        contractOrderId:{
          label: '合同编号',
          type: 'list',
          filterable: true,
          list: [],
          selectCallback: this.contractOrderIdSelectCallback
        },

        vouchType: {
          label: '款项类型',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {text: '应收款', label: 0},
            {text: '预付款', label: 1},
            {text: '其他费用', label: 2},
            {text: '调账（客户抹零）', label: 99},
          ],
          default: 0
        },
        clientId: {
          label: '客户名称',
          placeholder: '请输入客户名称',
          type: 'list',
          filterable: true,
          list: []
        },
        totalAmount: {
          label: '合同金额',
          type: 'number',
          placeholder: '合同金额',
          min: -10000,
          max: 10000000
        },
        amount: {
          label: '金额',
          type: 'number',
          placeholder: '请输入金额',
          min: -10000,
          max: 10000000
        },
        vouchDate: {
          label: '收款日期',
          type: 'date',
          placeholder: '请输入收款日期'
        },
        clientPayAmount:{
          label: '已付金额',
          type: 'number',
          disabled: true,
          placeholder: '请输入金额',
          max: 10000000
        },
        // itemName: {
        //   label: '项目名称',
        //   inputType: 'textarea',
        //   placeholder: '请输入用途，项目名称'
        // },
        remark:{
          label: '备注',
          inputType: 'textarea',
          placeholder: '请输入备注'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0
      this.initClientInfoList('clientId')
      this.initFinanceAccountInfoList('vouchAccount')
      this.initClientContractOrderOrderList('contractOrderId')

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('contractOrderId','clientId', 'vouchDate', 'vouchType', 'amount'),
        initApi: 'financeApi/financeOughtReceivableInfo',
        saveApi: 'financeApi/saveFinanceOughtReceivable',
        updateApi: 'financeApi/updateFinanceOughtReceivable',
        objectName: 'financeOughtReceive'
      })
    },
    contractOrderIdSelectCallback() {
      mRequest('contractApi/contractOrderInfoInfo', {id: this.dataForm.contractOrderId}, ({data}) => {
        this.dataForm['clientId'] = this.R.pathOr('', ['contractOrderInfo', 'clientId'], data)
        this.dataForm['clientPayAmount'] = this.R.pathOr(0, ['contractOrderInfo', 'clientPayAmount'], data)
        this.dataForm['totalAmount'] = this.R.pathOr(0, ['contractOrderInfo', 'totalAmount'], data)
      })
    }
  }
}
</script>
